function getSelectors(path) {
  return path.reverse().filter(el => el !== document && el !== window).map(item => {
    let selector = ''
    if (item.id) {
      return `${item.nodeName.toLowerCase()}#${item.id}`
    } else if (item.className && typeof item.className === 'string') {
      return `${item.nodeName.toLowerCase()}.${item.className}`
    } else {
      selector = item.nodeName.toLowerCase()
    }
    return selector
  }).join(' ')
}

export default function(pathsOrTarget) {
  if (Array.isArray(pathsOrTarget)) {
    return getSelectors(pathsOrTarget)
  } else {
    const paths = []
    let element = pathsOrTarget
    while(element) {
      paths.push(element)
      element = element.parentNode
    }
    return getSelectors(paths)
  }
}